import defaultSettings from './defaultSettings'; // https://umijs.org/config/

import path from 'path';
import slash from 'slash2';
import webpackPlugin from './plugin.config';
const { pwa, primaryColor } = defaultSettings; // preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
const publicPath = '/hshgis/';

const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {
        // default false
        enable: true,
        // default zh-CN
        default: 'zh-CN',
        // default true, when it is true, will use `navigator.language` overwrite default
        baseNavigator: true,
      },
      // dynamicImport: {
      //   loadingComponent: './components/PageLoading/index',
      //   webpackChunkName: true,
      //   level: 3,
      // },
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
        : false, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
      // dll features https://webpack.js.org/plugins/dll-plugin/
      // dll: {
      //   include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
      //   exclude: ['@babel/runtime', 'netlify-lambda'],
      // },
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      moveService: false,
      modifyRequest: true,
      autoAddMenu: true,
    },
  ],
]; // 针对 preview.pro.ant.design 的 GA 统计代码

if (isAntDesignProPreview) {
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // mock: {
  //   menuLayers:
  //   [
  //     {"gridId":0,"layerName":"dem","url":"http://121.36.101.98:6080/arcgis/rest/services/dem/MapServer"},
  //     {"gridId":1,"layerName":"lucc2010","url":"http://121.36.101.98:6080/arcgis/rest/services/lucc2010/MapServer"},
  //     {"gridId":2,"layerName":"lucc2015","url":"http://121.36.101.98:6080/arcgis/rest/services/lucc2015/MapServer"},
  //     {"gridId":3,"layerName":"鸟分布热力图","url":"http://121.36.101.98:6080/arcgis/rest/services/bird_thermograph/MapServer"}
  //   ]
  // },
  plugins,
  block: {
    // 国内用户可以使用码云
    // defaultGitUrl: 'https://gitee.com/ant-design/pro-blocks',
    defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  },
  hash: true,
  targets: {
    ie: 11,
  },
  devtool: isAntDesignProPreview ? 'source-map' : false,
  // umi routes: https://umijs.org/zh/guide/router.html
  routes: [
    {
      path: '/user',
      component: '../layouts/UserLayout',
      routes: [
        {
          name: 'login',
          path: '/user/login',
          component: './user/login',
        },
      ],
    },
    {
      path: '/',
      component: '../layouts/SecurityLayout',
      routes: [
        {
          path: '/',
          component: '../layouts/BasicLayout',
          authority: ['admin', 'user'],
          routes: [
            {
              path: '/',
              redirect: '/spaceResources',
            },
            {
              path: '/spaceResources',
              name: '空间资源',
              component: './SpaceResources',
            },
            {
              path: '/dataManager',
              name: '数据维护',
              redirect: '/graphicsOutput',
              routes: [
                {
                  path: '/graphicsOutput',
                  name: '制图输出',
                },
                {
                  path: '/vectorEditor',
                  name: '矢量编辑',
                },
              ],
            },
            { path: '/graphicsOutput', hideInMenu: true, component: './GraphicsOutput' },
            { path: '/vectorEditor', hideInMenu: true, component: './VectorEditor' },
            {
              path: '/patrolSpecial',
              name: '巡护专题',
              component: './PatrolSpecial',
            },
            {
              path: '/biodiversity',
              // path: '/biological',
              name: '衡水湖生态',
              // target: '_self',
              redirect: '/biological',
              // redirect: 'http://39.108.175.35:8080/hsh/wzbhyy/index.jhtml',
              routes: [
                {
                  // target: '_blank', // 点击新窗口打开
                  path: '/biological',
                  name: '生物多样性',
                  // component: './Biological',
                },
                {
                  path: '/birdsProject',
                  name: '鸟类分布',
                },
                {
                  path: '/monitor',
                  name: '生态监测',
                  routes: [
                    {
                      path: '/birdsMonitoring',
                      name: '生态聚类监测',
                    },
                    {
                      path: '/hydrologicalAnalysis',
                      name: '生态插值监测',
                    },
                  ],
                },
              ],
            },
            { path: '/biological', hideInMenu: true, component: './Biological' },
            { path: '/monitor', hideInMenu: true, component: './BirdsMonitoring' },
            { path: '/biodiversity', hideInMenu: true, component: './Biodiversity' },
            { path: '/birdsProject', hideInMenu: true, component: './BirdsProject' },
            { path: '/birdsMonitoring', hideInMenu: true, component: './BirdsMonitoring' },
            { path: '/rainfall', hideInMenu: true, component: './Rainfall' },
            { path: '/hydrologicalAnalysis',hideInMenu: true, component: './HydrologicalAnalysis'},
            { path: '/layerSetting',hideInMenu: true, component: './LayerSetting'},
            {
              path: '/admin',
              name: 'admin',
              icon: 'crown',
              component: './Admin',
              authority: ['admin'],
            },
            {
              component: './404',
            },
          ],
        },
        {
          component: './404',
        },
      ],
    },
    {
      component: './404',
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': primaryColor,
  },
  define: {
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
  },
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, _, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('.css') || //解决CSS文件加载失败的问题
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }

      const match = context.resourcePath.match(/src(.*)/);

      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }

      return localName;
    },
  },
  // manifest: {
  //   basePath: '/',
  // },
  // base:"/hshgis",
  // outputPath:"./dist/hshgis",
  // publicPath,
  chainWebpack: webpackPlugin,
  alias: {
    api: path.resolve(__dirname, '../src/services/'),
    components: path.resolve(__dirname, '../src/components'),
    assets: path.resolve(__dirname, '../src/assets'),
    utils: path.resolve(__dirname, '../src/utils'),
    services: path.resolve(__dirname, '../src/services'),
    models: path.resolve(__dirname, '../src/models'),
  },
  proxy: {
    '/arcgis': {
      // target: 'http://10.202.1.223:6080/',
      target: 'http://123.57.56.217:6080/',
      changeOrigin: true,
      pathRewrite: { '^/arcgis': '/arcgis' },
    },
    '/hsh': {
      //target: 'http://10.202.1.231:18080/',
      target: 'http://47.102.45.201:8085/',
      // target: 'http://121.36.94.43/',
      changeOrigin: true,
      pathRewrite: { '^/hsh': '/hsh' },
    },
  }
};
